#ifndef APPSETTINGS_H
#define APPSETTINGS_H

#include <QtCore/qvariant.h>

#define APPSETTINGS_FILENAME     "settings.ini"

class AppSettings
{
public:
    AppSettings();
    virtual ~AppSettings();

    void readAll();
    void writeAll();
    void writeSetting(const QString &key);

    QVariant get(const QString &key, const QVariant &defaultValue);
    void set(const QString &key, const QVariant &value);

    bool asBool(const QString &key, const QVariant &defaultValue = QVariant())
    { return get(key, defaultValue).toBool(); }
    double asDouble(const QString &key, const QVariant &defaultValue = QVariant())
    { return get(key, defaultValue).toDouble(); }
    int asInt(const QString &key, const QVariant &defaultValue = QVariant())
    { return get(key, defaultValue).toInt(); }
    QString asString(const QString &key, const QVariant &defaultValue = QVariant())
    { return get(key, defaultValue).toString(); }
    unsigned asUint(const QString &key, const QVariant &defaultValue = QVariant())
    { return get(key, defaultValue).toUInt(); }
    QByteArray asByteArray(const QString &key, const QVariant &defaultValue = QVariant())
    { return get(key, defaultValue).toByteArray(); }

private:
    QHash<QString, QVariant>     m_settings;
    bool                         m_isLoaded;
};

extern AppSettings *g_appSettings;

#endif // APPSETTINGS_H
